from django.db import models
from utils.basemodel import BaseModel


# Create your models here.
class Direction(BaseModel):
    name = models.CharField(max_length=20, verbose_name='方向')

    def __str__(self):
        return self.name

    class Mate:
        db_table = 'direction'


class Cate(BaseModel):
    name = models.CharField(max_length=20, verbose_name='分类')
    direction = models.ForeignKey(Direction, on_delete=models.SET_NULL, verbose_name='方向',blank=True,null=True)

    def __str__(self):
        return self.name

    class Mate:
        db_table = 'cate'


class Level(models.Model):
    name = models.CharField(max_length=20, verbose_name='难度')


class Teacher(BaseModel):
    name= models.CharField(max_length=20, verbose_name='教师')
    job = models.CharField(max_length=20, verbose_name='职位')
    img = models.CharField(max_length=2000, verbose_name='图片')
    intro = models.CharField(max_length=200, verbose_name='简介')


class Course(BaseModel):
    name = models.CharField(max_length=20, verbose_name='课程')
    cate = models.ForeignKey(Cate, on_delete=models.SET_NULL, verbose_name='分类',blank=True,null=True)
    img = models.CharField(max_length=200, verbose_name='图片')
    video = models.CharField(max_length=200, verbose_name='视频',default='http://127.0.0.1:8000/uploads/course/video/1.mp4')
    level = models.ForeignKey(Level, on_delete=models.SET_NULL, verbose_name='难度',blank=True,null=True)
    price = models.IntegerField(verbose_name='价格')
    sell = models.IntegerField(verbose_name='销量')
    teacher = models.ForeignKey(Teacher, on_delete=models.SET_NULL, verbose_name='教师',blank=True,null=True,default=1)
    ishot= models.BooleanField(default=False, verbose_name='是否热门')
    isnew = models.BooleanField(default=True, verbose_name='是否最新')
    ishome= models.BooleanField(default=False, verbose_name='是否首页推荐')

    def __str__(self):
        return self.name

    class Mate:
        db_table = 'course'